﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dancer_Partner_Matching
{
    class Program
    {
        static void Main(string[] args)
        {            
            var matcher = new PartnerMatcher();

            var m_huang = new Dancer("M_黄");
            var m_zhang = new Dancer("M_张");
            var m_liang = new Dancer("M_梁");

            var f_lan = new Dancer("F_蓝");
            var f_hong = new Dancer("F_红");
            var f_qing = new Dancer("F_青");

            m_huang.Prefs = new List<Dancer>() { f_lan, f_hong, f_qing };
            m_zhang.Prefs = new List<Dancer>() { f_hong, f_qing, f_lan };
            m_liang.Prefs = new List<Dancer>() { f_qing, f_lan, f_hong };

            f_lan.Prefs = new List<Dancer>() { m_huang, m_zhang, m_liang };
            f_hong.Prefs = new List<Dancer>() { m_liang, m_zhang, m_huang };
            f_qing.Prefs = new List<Dancer>() { m_zhang, m_huang, m_liang };

            var males = new List<Dancer>() { m_huang, m_zhang, m_liang };
            var females = new List<Dancer>() { f_lan, f_qing, f_hong };

            matcher.Matching(males);
            PrintResult(males);
            Console.WriteLine("Stable: {0}", matcher.IsStable(males, females));

            Console.WriteLine();
            Console.WriteLine("Swithching m_huang & m_liang 's partner...");
            var f_lan_of_m_huang = m_huang.Partner;
            var f_qing_of_m_liang = m_liang.Partner;
            m_huang.SetPartner(f_qing_of_m_liang);
            m_liang.SetPartner(f_lan_of_m_huang);

            Console.WriteLine();
            PrintResult(males);
            Console.WriteLine("Stable: {0}", matcher.IsStable(males, females));

            Console.ReadKey();
        }

        static void PrintResult(List<Dancer> males)
        {
            foreach (var male in males)
                Console.WriteLine("{0} 's Partner is {1}", male.Name, male.Partner.Name);
        }
    }
}